<%-- 
    Document   : flightPage
    Created on : Sep 6, 2011, 12:43:50 PM
    Author     : VANTRUY
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="rich" uri="http://richfaces.ajax4jsf.org/rich"%>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<%@taglib prefix="p" uri="http://primefaces.prime.com.tr/ui"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<f:view>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <title>JSP Page</title>
            <link type="text/css" rel="stylesheet" href="le-frog/skin.css"/>
            <p:resources/>
        </head>


        <body>
            <h:form>
                <a4j:outputPanel ajaxRendered="true">
                    <p:growl id="growl" showDetail="true" life="5000" />
                </a4j:outputPanel>
                <h:panelGroup id="listFlight">
                    <rich:dataTable onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
                                    onmouseout="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
                                    cellpadding="0" cellspacing="0" rowKeyVar="row" width="700" border="0"
                                    var="list" value="#{FC.listFlight}">
                        <f:facet name="header">
                            <rich:columnGroup>
                                <rich:column>
                                    <h:outputLabel value="No"/>
                                </rich:column>
                                <rich:column>
                                    <h:outputLabel value="FlightID"/>
                                </rich:column>
                                <rich:column>
                                    <h:outputLabel value="TicketType"/>
                                </rich:column>
                                <rich:column>
                                    <h:outputLabel value="Price"/>
                                </rich:column>
                                <rich:column>
                                    <h:outputLabel value="DepartTime"/>
                                </rich:column>
                                <rich:column>
                                    <h:outputLabel value="Description"/>
                                </rich:column>
                                <rich:column width="100px">
                                    <h:outputLabel value="Tool"/>
                                </rich:column>
                            </rich:columnGroup>
                        </f:facet>
                        <rich:column>
                            <h:outputLabel value="#{row+1}"/>
                        </rich:column>
                        <rich:column>
                            <h:outputLabel value="#{list.flightID}" />
                        </rich:column>
                        <rich:column>
                            <h:outputLabel value="#{list.flightName}" />
                        </rich:column>
                        <rich:column>
                            <h:outputLabel value="#{list.ticketType}" />
                        </rich:column>
                        <rich:column>
                            <h:outputLabel value="#{list.price}" />
                        </rich:column>
                        <rich:column>
                            <h:outputLabel value="#{list.departTime}" >
                            <f:convertDateTime locale="vi" pattern="dd/MM/yyyy"/>
                            </h:outputLabel>
                        </rich:column>
                        <rich:column>
                            <h:outputLabel value="#{list.description}" />
                        </rich:column>
                        <rich:column>

                            <%-----------Update----------%>

                            <a4j:commandLink id="updateLink" oncomplete="#{rich:component('updatePanel')}.show()"
                                             action="#{FC.setSessionUp}" >
                                <h:graphicImage value="edit_u.gif" style="border:0.height:30px;width:30px"/>
                                <f:setPropertyActionListener value="#{list}" target="#{FC.f}" />
                            </a4j:commandLink>
                            <rich:toolTip for="updateLink" value="Update Flight" />

                            <%-----------Delete----------%>

                            <a4j:commandLink id="deleteLink" action="#{FC.setSessionDel}"
                                             oncomplete="#{rich:component('deletePanel')}.show()" >
                                <h:graphicImage value="icon/btnCancel.png" style="border:0.height:20px;width:20px"/>
                                <f:setPropertyActionListener value="#{list}" target="#{FC.f}" />
                            </a4j:commandLink>
                            <rich:toolTip for="deleteLink" value="Delete Flight"/>
                        </rich:column>
                    </rich:dataTable>

                    <%-----------Add ----------%>

                    <a4j:commandLink id="addLink" oncomplete="#{rich:component('addPanel')}.show()" >
                        <h:graphicImage value="icon/Add2.png" style="border:0.height:100px;width:50px"/>
                    </a4j:commandLink>
                    <rich:toolTip for="addLink" value="Add new Flight"/>
                </h:panelGroup>
            </h:form>

            <%------------------------Panel Add new course -------------------------------%>

            <rich:modalPanel id="addPanel" autosized="true" width="500">
                <f:facet name="header">
                    <h:outputLabel value="Add new Flight " />
                </f:facet>
                <f:facet name="controls">
                    <h:panelGroup>
                        <h:graphicImage value="close.png" id="addHide" styleClass="hidelink" style="height:30px;width:30px;" />
                        <rich:componentControl for="addPanel" attachTo="addHide" operation="hide" event="onclick"/>
                    </h:panelGroup>
                </f:facet>
                <h:form>
                    <a4j:outputPanel ajaxRendered="true">
                        <h:panelGrid columns="2">

                            <h:outputLabel value="FlightName(*):"/>
                            <h:inputText value="#{FC.f.flightName}">
                                <rich:beanValidator summary="Invalid data"/>
                            </h:inputText>
                            <h:outputLabel value="TicketType(*):"/>
                            <h:inputText value="#{FC.f.ticketType}">
                                <rich:beanValidator summary="Invalid data"/>
                            </h:inputText>

                            <h:outputLabel value="Price(*):"/>
                            <h:inputText value="#{FC.f.price}">
                                <rich:beanValidator summary="Invalid data"/>
                            </h:inputText>

                            <h:outputLabel value="DepartTime(*):"/>
                            <rich:calendar value="#{FC.f.departTime}"
                                           popup="true"
                                           datePattern="dd/MM/yyyy"
                                           cellWidth="24px"
                                           cellHeight="22px" style="width:200px">
                                <rich:beanValidator summary="StartDate invalid"/>
                            </rich:calendar>

                            <h:outputLabel value="Decsription :"/>
                            <h:inputTextarea value="#{FC.f.description}">

                            </h:inputTextarea>

                        </h:panelGrid>
                    </a4j:outputPanel>
                    <a4j:commandButton value="Save" action="#{FC.insertFlight}"
                                       reRender="listFlight" oncomplete="if(#{FC.error==0})#{rich:component('addPanel')}.hide();" />
                </h:form>
            </rich:modalPanel>
            <%-------------------------Panel Delete----------------------------------------%>

            <rich:modalPanel id="deletePanel" autosized="true" width="300">
                <f:facet name="header">
                    <h:outputLabel value="Delete Panel" />
                </f:facet>
                <f:facet name="controls">
                    <h:panelGroup>
                        <h:graphicImage value="delete.png" id="closeDelete" styleClass="hidelink"
                                        style="height:30px;width:30px;" />
                        <rich:componentControl for="deletePanel" attachTo="closeDelete"
                                               operation="hide" event="onclick"/>
                    </h:panelGroup>
                </f:facet>
                <h:form>
                    <a4j:outputPanel ajaxRendered="true" style="text-align:center;">
                        <center>
                            <h:panelGrid columns="3">
                                <h:outputLabel value="Are you sure ? : "/>
                                <a4j:commandButton value="Cancel"oncomplete="#{rich:component('deletePanel')}.hide();" />

                                <a4j:commandButton value="Ok" action="#{FC.deleteFlight}"
                                                   reRender="listFlight" oncomplete="#{rich:component('deletePanel')}.hide();" />
                            </h:panelGrid>
                        </center>
                    </a4j:outputPanel>
                </h:form>
            </rich:modalPanel>
            
             <%-------------------------Panel Update course----------------------------------------%>

            <rich:modalPanel id="updatePanel" autosized="true" width="500">
                <f:facet name="header">
                    <h:outputLabel value="Update flight " />
                </f:facet>
                <f:facet name="controls">
                    <h:panelGroup>
                        <h:graphicImage value="close.png" id="updateHide" styleClass="hidelink"
                                        style="height:30px;width:30px;" />
                        <rich:componentControl for="updatePanel" attachTo="updateHide"
                                               operation="hide" event="onclick"/>
                    </h:panelGroup>
                </f:facet>
                <h:form>
                    <a4j:outputPanel ajaxRendered="true">
                        <h:panelGrid columns="2">
                            <h:outputLabel value="FlightName(*):"/>
                            <h:inputText value="#{FC.f.flightName}">
                                <rich:beanValidator summary="Invalid data"/>
                            </h:inputText>
                            <h:outputLabel value="TicketType(*):"/>
                            <h:inputText value="#{FC.f.ticketType}">
                                <rich:beanValidator summary="Invalid data"/>
                            </h:inputText>

                            <h:outputLabel value="Price(*):"/>
                            <h:inputText value="#{FC.f.price}">
                                <rich:beanValidator summary="Invalid data"/>
                            </h:inputText>

                            <h:outputLabel value="DepartTime(*):"/>
                            <rich:calendar value="#{FC.f.departTime}"
                                           popup="true"
                                           datePattern="dd/MM/yyyy"
                                           cellWidth="24px"
                                           cellHeight="22px" style="width:200px">
                                <rich:beanValidator summary="StartDate invalid"/>
                            </rich:calendar>

                            <h:outputLabel value="Decsription :"/>
                            <h:inputTextarea value="#{FC.f.description}">

                            </h:inputTextarea>


                        </h:panelGrid>
                    </a4j:outputPanel>
                        <a4j:commandButton value="Update" action="#{FC.updateFlight}" reRender="listFlight"
                                       oncomplete="if(#{FC.error==0})#{rich:component('updatePanel')}.hide();" />
                </h:form>

            </rich:modalPanel>

        </body>
    </html>
</f:view>
